package com.cc.visitor.config;

import com.cc.visitor.utils.DynamicScheduledTaskRegistrar;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * @author chanchaw
 * @create 2024-10-10 15:10
 */
@Configuration
public class SystemConfig {
    @Bean("dynamicScheduledTaskRegistrar")
    public DynamicScheduledTaskRegistrar initTaskRegistrar(){
        return new DynamicScheduledTaskRegistrar();
    }

    /**````
     * 2024年10月10日 15:11:43 依赖 com.github.penggle.kaptcha
     * 的验证码工具配置
     * @return
     */
    @Bean("kaptcha")
    public DefaultKaptcha getDefaultKaptcha(){
        com.google.code.kaptcha.impl.DefaultKaptcha defaultKaptcha = new com.google.code.kaptcha.impl.DefaultKaptcha();
        Properties properties = new Properties();
        properties.put("kaptcha.border", "no");
        properties.put("kaptcha.textproducer.font.color", "red");
        properties.put("kaptcha.image.width", "170");
        properties.put("kaptcha.image.height", "65");
        properties.put("kaptcha.textproducer.font.size", "45");
        properties.put("kaptcha.session.key", "verifyCode");
        properties.put("kaptcha.textproducer.char.space", "6");
        properties.put("kaptcha.obscurificator.impl", "com.google.code.kaptcha.impl.WaterRipple");
        properties.put("kaptcha.textproducer.font.names", "宋体,楷体,微软雅黑");
        properties.put("kaptcha.background.clear.from", "yellow");
        properties.put("kaptcha.background.clear.to", "green");

        properties.put("kaptcha.textproducer.char.length", "4");
        properties.put("kaptcha.textproducer.impl", "com.cc.visitor.config.KaptchaTextCreator");
        Config config = new Config(properties);
        defaultKaptcha.setConfig(config);
        return defaultKaptcha;
    }
}
